package com.mapull.compare;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Java 比较
 * @author mapull
 */
public class MapullCompare {

    public static void main(String[] args) {
//        comparePerson();
        compareAnimal();
    }
    private static void comparePerson(){
        Person person1 = new Person();
        person1.setAge(22);
        person1.setName("Tom");

        Person person2 = new Person();
        person2.setAge(33);
        person2.setName("Jerry");

        Person person3 = new Person();
        person3.setAge(6);
        person3.setName("Baby");

        List<Person> people = new ArrayList<>();
        people.add(person1);
        people.add(person2);
        people.add(person3);

        System.out.println("排序前    " + people);
        Collections.sort(people);
        System.out.println("排序后    " + people);
        Collections.reverse(people);
        System.out.println("反向排序后 " + people);
    }

    private static void compareAnimal(){
        Animal dog = new Animal();
        dog.setName("狗");
        dog.setWeight(10);

        Animal chicken = new Animal();
        chicken.setName("鸡");
        chicken.setWeight(2);

        Animal pig = new Animal();
        pig.setName("猪");
        pig.setWeight(60);

        List<Animal> animals = new ArrayList<>();
        animals.add(dog);
        animals.add(chicken);
        animals.add(pig);

        System.out.println("排序前    " + animals);
        animals.sort(new AnimalComparator());
        System.out.println("排序后    " + animals);
        Collections.reverse(animals);
        System.out.println("反向排序后 " + animals);
    }
}
